<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>原型链</title>
</head>
<body>
<h1>请看控制台</h1>
<script>

  /* -------------------- 原型链----------------------*/
   /* var a={
        x:10,
        calculate:function(z){
            return this.x+this.y+z
        }
    };
    var b={
        y:20,
        __proto__:a//下划线有两次
    };
    var c={
        y:30,
        __proto__:a
    };
    console.log( b.calculate(30));
    console.log( c.calculate(40));*/
    //a constructor function
    function Foo(y){
        this.y=y;
    }
    Foo.prototype.x=10;
    Foo.prototype.calculate=function (z){
        return this.x+this.y+z;
    };
    var b=new Foo(20);
    var c=new Foo(30);
  console.log( b.calculate(30));
  console.log( c.calculate(40));
  console.log(
          b.__proto__===Foo.prototype,
          c.__proto__===Foo.prototype,
          b.constructor===Foo,
          c.constructor===Foo,
          Foo.prototype.constructor===Foo,
          b.__proto__.calculate===Foo.prototype.calculate
  );

var x=10;
  (function foo(){
      var y=20;
      (function bar(){
          var z=30;
          console.log(x+y+z);
      })()
  })()












</script>
</body>
</html>